import React from "react";
import { NavBar } from "antd-mobile";
import {useNavigate, useLocation, useSearchParams} from 'react-router-dom'
import  PropTypes  from "prop-types";

const NavBarAgain = function (props) {
    let {title} = props;
    let navigate = useNavigate(),
        location = useLocation(),
        [usp] = useSearchParams();
        let to = usp.get('to')
    const handleBack = () => {
        if(location.pathname === '/login' && /^\/detail\/\d+$/.test(to)){
            navigate(to, {replace: true});
            return;
        }
        navigate(-1);
    }
    return <NavBar onBack={handleBack}>{title}</NavBar>
}
NavBarAgain.defaultProps = {
    title:"个人中心"
}
NavBarAgain.propTypes = {
    title: PropTypes.string
}
export default NavBarAgain;